#include "rclcpp/rclcpp.hpp"
#include "base_interface_demo01/msg/stu.hpp"
using base_interface_demo01::msg::Stu;
using namespace std::chrono_literals;
class TalkerStu: public rclcpp::Node
{
public:  
  TalkerStu():Node("talker_stu_node_cpp")
  {
    RCLCPP_INFO(this->get_logger(),"cpp发布节点");
    this->age=0;
    publisher_ = this->create_publisher<Stu>("chatter_stu", 10);
    timer_ = this->create_wall_timer(500ms, std::bind(&TalkerStu::on_timer, this));
  }

private:
    rclcpp::Publisher<Stu>::SharedPtr publisher_;
    rclcpp::TimerBase::SharedPtr timer_; // 定时指针
    int age=0;
    void on_timer()
    {
        Stu stu=Stu();
        stu.set__age(this->age);
        this->age++;
        stu.set__name("葫芦娃");
        stu.set__height(156.66);
        RCLCPP_INFO(this->get_logger(), 
        "发布订阅消息 (name=%s,age=%d,height%.2f)",stu.name.c_str(),stu.age,stu.height);
        publisher_->publish(stu);
    }

};
int main(int argc, char ** argv)
{
    rclcpp::init(argc,argv);
    rclcpp::spin(std::make_shared<TalkerStu>());
    rclcpp::shutdown();
    return 0;
}